# 大类：经营状况
# 小类：资质证书

import json
import time


# 21-资质证书数据-2018-05-26
def get_certificate(mongo_instance, soup, cid, company):
    print('start 资质证书数据*******')

    if soup.find('div', id='_container_certificate'):

        for tr in soup.find('div', id='_container_certificate').find('tbody').find_all('tr'):
            item = {}
            tds = tr.find_all('td')
            item['type'] = tds[1].text  # 证书类型
            item['code'] = tds[2].text  # 证书编号
            item['publish_date'] = tds[3].text  # 发证日期
            item['end_date'] = tds[4].text  # 截止日期
            item['create_at'] = int(time.time())
            item['update_at'] = item['create_at']
            item['company'] = company
            item['company_id'] = cid
            print(item)
            mongo_instance.certificate.update({'company_id': cid}, item, True)

    print('success 资质证书数据*******')
